package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.product.service.BaseTrademarkService;

import org.springframework.web.bind.annotation.RestController;

/**
 * 品牌表 前端控制器
 *
 * @author atguigu
 * @since 2023-04-18
 */
@Api(tags = "品牌表控制器")
@RestController
@RequestMapping("/admin/product") //TODO 填写基础映射URL
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    /**
     * 查询品牌管理分页列表
     * @param page
     * @param limit
     * @return
     */
   @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getBaseTrademark(@PathVariable("page") Long page, @PathVariable("limit") Long limit){
       Page<BaseTrademark> page1 = new Page<>(page, limit);
       Page<BaseTrademark> baseTrademarkPage= baseTrademarkService.getBaseTrademark(page1);
       return Result.ok(baseTrademarkPage);
   }

    /**
     * 新增
     * @param baseTrademark
     * @return
     */
    @PostMapping("baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
       baseTrademarkService.save(baseTrademark);
       return Result.ok();
    }

    /**
     * 更新
     * @param baseTrademark
     * @return
     */
    @PutMapping("baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
    baseTrademarkService.updateById(baseTrademark);
    return Result.ok();
    }

    /**
     * 根据品牌Id 获取品牌对象
     * @param id
     * @return
     */
    @GetMapping("baseTrademark/get/{id}")
    public Result get(@PathVariable Long id){
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }

    @DeleteMapping("baseTrademark/remove/{id}")
    public Result remove(@PathVariable("id") Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

}
